
def read_text_file(file):
    with open(file, 'r', encoding='utf8') as f:
        return f.read()
    
def write_text_file(file, byte_array):
    with open(file, 'wb') as f:
        f.write(byte_array)
    

text = read_text_file('gif_text_data.txt')
# print(text)

lines = text.split('\n')
byte_array = bytearray()
for line in lines:
    # 使用split方法按照'//'分割字符串
    parts = line.split('//', 1)
    # 返回第一个部分，即'//'前的内容，并去除首尾的空白字符
    fstr = parts[0].strip()
    strnums = fstr.split(' ')
    for num in strnums:
        value = int(num)
        byte_value = value.to_bytes(1, byteorder='big')
        byte_array.append(byte_value[0])

write_text_file('gif_text_data.gif', byte_array)